﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Xml.Linq;

namespace Utils
{
    public class SetConfig
    {
        /// <summary>
        /// 当前默认模板
        /// </summary>
        /// <returns></returns>
        public static string GetDefaultTempate()
        {
            string xmlpath = FileHelper.RootPath() + "/config/setConfig.xml";
            XElement root = XElement.Load(xmlpath);
            XElement dt = root.Element("defaultTemplate");
            if (dt.HasAttributes)
            {
                foreach (var attr in dt.Attributes())
                {
                    if (attr.Name == "path")
                    {
                        return attr.Value;
                    }
                }
            }
            MessageBox.Show("无法获取默认设置!");
            return "";
        }
        /// <summary>
        /// 获取包名或命名空间
        /// </summary>
        /// <returns></returns>
        public static string GetPackage()
        {
            string xmlpath = FileHelper.RootPath() + "/config/setConfig.xml";
            XElement root = XElement.Load(xmlpath);
            XElement dt = root.Element("package");
            if (dt.HasAttributes)
            {
                foreach (var attr in dt.Attributes())
                {
                    if (attr.Name == "value")
                    {
                        return attr.Value;
                    }
                }
            }
            MessageBox.Show("无法获取默认设置!");
            return "";
        }
        /// <summary>
        /// 获取当前的数据库类型
        /// </summary>
        /// <returns></returns>
        public static string GetDbType()
        {
            string xmlpath = FileHelper.RootPath() + "/config/setConfig.xml";
            XElement root = XElement.Load(xmlpath);
            XElement dt = root.Element("dbType");
            if (dt.HasAttributes)
            {
                foreach (var attr in dt.Attributes())
                {
                    if (attr.Name == "value")
                    {
                        return attr.Value;
                    }
                }
            }
            MessageBox.Show("无法获取默认当前的数据库类型!");
            return "";
        } 
        /// <summary>
        /// 获取当前的数据库类型
        /// </summary>
        /// <returns></returns>
        public static string GetDataType()
        {
            string xmlpath = FileHelper.RootPath() + "/config/setConfig.xml";
            XElement root = XElement.Load(xmlpath);
            XElement dt = root.Element("dataType");
            if (dt.HasAttributes)
            {
                foreach (var attr in dt.Attributes())
                {
                    if (attr.Name == "value")
                    {
                        return attr.Value;
                    }
                }
            }
            MessageBox.Show("无法获取默认当前的数据类型关系!");
            return "";
        }
    }
}
